package com.chenfeng.back.controller;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.chenfeng.common.controller.BaseConroller;
import com.chenfeng.common.util.ConstantFinalUtil;
import com.chenfeng.common.util.PageInfoUtil;
import com.chenfeng.system.pojo.ACate;
import com.chenfeng.system.pojo.ARegion;
import com.chenfeng.system.service.ISystemService;


@RequestMapping("/back/system")
@Controller
public class SysBackController extends BaseConroller
{
	@Resource
	ISystemService iSystemService;
	@RequestMapping("/regionListSubmit.htm")
	public String regionListSubmit(HttpServletRequest request)
	{
		ConstantFinalUtil.LOGGER_SYSTEM.info("regionList");
		String keyword = request.getParameter("keyword");
		String parentId = request.getParameter("parentId");
		String status = request.getParameter("status");
		String st = request.getParameter("st");
		String ed = request.getParameter("ed");
		System.out.println("et:"+st+"sd"+ed);
		if(st == null)
		{
			st ="";
		}
		if(ed == null)
		{
			ed = "";
		}
		Date stDate = null;
		Date edDate = null;
		if(!"".equalsIgnoreCase(st)&&!"".equalsIgnoreCase(ed))
		{
			//将字符串转换成时间
			stDate = this.dateFormatUtil.parseDateTime(st);
			edDate = this.dateFormatUtil.parseDateTime(ed);		
		}
		//分页查询
		PageInfoUtil pageInfoUtil = this.proccedPageInfo(request);
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("keyword", keyword);
		map.put("status", status);
		map.put("stDate", stDate);
		map.put("edDate", edDate);
		map.put("parentId", parentId);
		//查询满足条件的结果
		List<ARegion> regionList = this.iSystemService.findCondListRegion(pageInfoUtil, map);
		//存储结果
		request.setAttribute("regionList", regionList);
		request.setAttribute("pageInfoUtil", pageInfoUtil);
		//存储条件
		request.setAttribute("keyword", keyword);
		request.setAttribute("status", status);
		request.setAttribute("st", st);
		request.setAttribute("ed", ed);
		request.setAttribute("parentId", parentId);
		ConstantFinalUtil.LOGGER_SYSTEM.info("regionList{}",regionList);
		ConstantFinalUtil.LOGGER_SYSTEM.info("regionListSubmit");
		return "/back/system/regionList";
	}
	//=========================================分类============================================================
	@RequestMapping("/cateListSubmit.htm")
	public String cateListSubmit(HttpServletRequest request)
	{
		ConstantFinalUtil.LOGGER_SYSTEM.info("cateList");
		String keyword = request.getParameter("keyword");
		String parentId = request.getParameter("parentId");
		String status = request.getParameter("status");
		String st = request.getParameter("st");
		String ed = request.getParameter("ed");
		System.out.println("et:"+st+"sd"+ed);
		if(st == null)
		{
			st ="";
		}
		if(ed == null)
		{
			ed = "";
		}
		Date stDate = null;
		Date edDate = null;
		if(!"".equalsIgnoreCase(st)&&!"".equalsIgnoreCase(ed))
		{
			//将字符串转换成时间
			stDate = this.dateFormatUtil.parseDateTime(st);
			edDate = this.dateFormatUtil.parseDateTime(ed);		
		}
		//分页查询
		PageInfoUtil pageInfoUtil = this.proccedPageInfo(request);
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("keyword", keyword);
		map.put("status", status);
		map.put("stDate", stDate);
		map.put("edDate", edDate);
		map.put("parentId", parentId);
		//查询满足条件的结果
		List<ACate> cateList = this.iSystemService.findCondListCate(pageInfoUtil, map);
		//存储结果
		request.setAttribute("cateList", cateList);
		request.setAttribute("pageInfoUtil", pageInfoUtil);
		//存储条件
		request.setAttribute("keyword", keyword);
		request.setAttribute("status", status);
		request.setAttribute("st", st);
		request.setAttribute("ed", ed);
		request.setAttribute("parentId", parentId);
		ConstantFinalUtil.LOGGER_SYSTEM.info("cateList{}",cateList);
		ConstantFinalUtil.LOGGER_SYSTEM.info("cateListSubmit");
		return "/back/system/cateList";
	}
}
